#include "CControlTool.h"
#include <QUuid>
#include <QSysInfo>
#include <QCryptographicHash>
#include <QRandomGenerator>

NETWORKSERVICE_BEGIN_NAMESPACE

// 重启原因保存
#define REBOOT_LOG_FILE "rebootLog.josn"
// 系统重启前保存信息
#define REBOOT_INFO_FILE "rebootInfo.josn"

// 延时启动定时器时间计数器
int CControlTool::m_delayTimerNum = 1;
int CControlTool::m_ventNum = 1;

// 获取字符串md5
string CControlTool::strMd5(const string &str)
{
    // 将输入转换为字节数组
    QByteArray byteArray = QByteArray::fromStdString(str);
    QCryptographicHash myHash(QCryptographicHash::Md5);
    myHash.addData(byteArray);
    QByteArray hashResult = myHash.result();

    return QString(hashResult.toHex()).toStdString();

}

// 获取签名信息
string CControlTool::getSignature(const string &body)
{
	return strMd5(strMd5(body));
}


// 获取设备sn
string CControlTool::getDevSn()
{
	string sn ="";

    QByteArray uniqueId = QSysInfo::machineUniqueId();
    QString id = QString::fromLatin1(uniqueId.toHex());


    sn = "win"+id.toStdString();

	return sn;
}



// 获取随机唯一ID
string CControlTool::getOnlyId()
{
    return QUuid::createUuid().toString().toStdString();

}
NETWORKSERVICE_END_NAMESPACE
